﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL
{
    public class ResponseDAO : ObjectDAO, IResponse
    {
        public ResponseDAO() : base() { }

        public System.Linq.IQueryable<Response> FindAllResponses()
        {
            return jassEntities.Responses;
        }

        public Response GetResponse(int responseId)
        {
            return jassEntities.Responses.SingleOrDefault(c => c.Id == responseId);
        }

        public void AddResponse(Response response)
        {
            jassEntities.AddToResponses(response);
            Save();
        }

        public void UpdateResponse(Response response)
        {
            jassEntities.Responses.ApplyCurrentValues(response);
            Save();
        }

        public void DeleteResponse(int responseId)
        {
            Response response = GetResponse(responseId); ;
            jassEntities.Responses.DeleteObject(response);
            Save();
        }


        public IQueryable<Response> FindAllResponsesByUser(Guid userId)
        {
            return jassEntities.Responses.Where(m => m.UserId == userId);
        }
    }

    public class ResponseActionsDAO : ObjectDAO, IResponseActions
    {
        public ResponseActionsDAO() : base() { }

        public System.Linq.IQueryable<ResponseAction> FindAllResponseActions()
        {
            return jassEntities.ResponseActions;
        }

        public ResponseAction GetResponseAction(int responseActionId)
        {
            return jassEntities.ResponseActions.SingleOrDefault(c => c.Id == responseActionId);
        }

        public void AddResponseAction(ResponseAction responseAction)
        {
            jassEntities.AddToResponseActions(responseAction);
            Save();
        }

        public void UpdateResponseAction(ResponseAction responseAction)
        {
            jassEntities.ResponseActions.ApplyCurrentValues(responseAction);
            Save();
        }

        public void DeleteResponseAction(int responseActionId)
        {
            ResponseAction responseAction = GetResponseAction(responseActionId); ;
            jassEntities.ResponseActions.DeleteObject(responseAction);
            Save();
        }
    }

    public class ActionsDAO : ObjectDAO, IActions
    {
        public ActionsDAO() : base() { }

        public System.Linq.IQueryable<Action> FindAllActions()
        {
            return jassEntities.Actions;
        }

        public Action GetAction(int actionId)
        {
            return jassEntities.Actions.SingleOrDefault(c => c.Id == actionId);
        }

        public void AddAction(Action action)
        {
            jassEntities.AddToActions(action);
            Save();
        }

        public void UpdateAction(Action action)
        {
            jassEntities.Actions.ApplyCurrentValues(action);
            Save();
        }

        public void DeleteAction(int actionId)
        {
            Action action = GetAction(actionId); ;
            jassEntities.Actions.DeleteObject(action);
            Save();
        }
    }

    public class AddressesDAO : ObjectDAO, IAddresses
    {
        public AddressesDAO() : base() { }

        public System.Linq.IQueryable<Address> FindAllAddresses()
        {
            return jassEntities.Addresses;
        }

        public Address GetAddress(int actionId)
        {
            return jassEntities.Addresses.SingleOrDefault(c => c.Id == actionId);
        }

        public void AddAddress(Address action)
        {
            jassEntities.AddToAddresses(action);
            Save();
        }

        public void UpdateAddress(Address action)
        {
            jassEntities.Addresses.ApplyCurrentValues(action);
            Save();
        }

        public void DeleteAddress(int actionId)
        {
            Address action = GetAddress(actionId); ;
            jassEntities.Addresses.DeleteObject(action);
            Save();
        }
    }

}
